home *** CD-ROM | disk | FTP | other *** search
- Path: tools.bbnplanet.com!not-for-mail
- From: barmar@tools.bbnplanet.com (Barry Margolin)
- Newsgroups: comp.infosystems.www.misc,comp.lang.misc,comp.lang.perl.misc,comp.lang.c
- Subject: Re: Perl vs. C (was Re: Unix or NT? Get a Mac!)
- Date: 6 Jan 1996 16:20:57 -0500
- Organization: BBN Planet Corp., Cambridge, MA
- Message-ID: <4cmp3p$5ln@tools.bbnplanet.com>
- References: <4cgfp9$pje@hecate.umd.edu> <4cji0c$21e@hecate.umd.edu> <4ckm4l$4vu@tools.bbnplanet.com> <4cksih$goq@hecate.umd.edu>
- NNTP-Posting-Host: tools.bbnplanet.com
-
- In article <4cksih$goq@hecate.umd.edu>, Ram Samudrala <me@ram.org> wrote:
- >In all my experience with programming contests, I've never had to
- >resort to any complex functions or features of a specific language
- >(which C has a few of, but I think it just gets you into trouble)---in
- >fact, I prefer using standard Pascal than anything else. I prefer the
- >Occam's razor approach, and I really don't see how using Perl could
- >make it "far too easy".
-
- Well, a couple of years ago I wanted to add some features and bug fixes to
- a program at my former employer. The program was our internal variant of
- "finger"; it looked people up in our employee file, allowing you to specify
- first name, last name, Unix username, nicknames, or even substrings. The
- program was about 2,000 lines of C, which included some home-grown
- libraries for parsing the data files (just flat files somewhat like
- /etc/passwd format) and memory management; it was written by a Lisp
- programmer, so it did lots of stuff using linked lists and
- dynamically-growing arrays. And even with those memory management
- routines, the program had some hard-coded limitations -- if a name was
- ambiguous, only 10 matching names would be displayed.
-
- In a weekend I rewrote the program into about 500 lines of Perl. All the
- parsing and memory management routines were replaced with Perl's built-in
- arrays and the split() function. One of the bugs I was fixing was that an
- employee might be listed twice, because the parameter matched more than one
- of the fields; I fixed this by using Perl's associative arrays. Searching
- for matching names was quite easy using Perl's string matching operators.
- One of the enhancements I was making was for it to generate both HTML and
- human-oriented output (so the program could be used from a CGI script on
- our internal web server); Perl's output handling made it relatively easy to
- put optional HTML output throughout the program.
-
- I did have some performance problems with my initial version. I found a
- simple optimization and the result was that the Perl version was as fast as
- the original C version. On the other hand, it had no coded limits and had
- more features (well, to be honest, while I was at it I removed some
- obsolete features that were no needed).
- --
- Barry Margolin
- BBN PlaNET Corporation, Cambridge, MA
- barmar@bbnplanet.com
- Phone (617) 873-3126 - Fax (617) 873-6351
-